# @Time    : 2022/2/10 23:25
# @Author  : junbaibai
# @File    : __init__.py.py
import json

conf_path = "static/conf.json"


class Configuration:
    __slots__ = ["_listening_path"]

    def __init__(self):
        with open(conf_path, "r", encoding="utf-8") as fp:
            c = json.load(fp)
            self._listening_path = c.get("_listening_path")

    @property
    def listening_path(self):
        return self._listening_path

    @listening_path.setter
    def listening_path(self, string):
        self._listening_path = string
        self._save()

    def _save(self):
        with open(conf_path, "w", encoding="utf-8") as fp:
            d = {}
            for key in self.__slots__:
                d.update({
                    key: getattr(self, key)
                })
            json.dump(d, fp, indent=4)


conf = Configuration()
